package com.cskaoyan.service.wx;

import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.mapper.wx.WxAuthMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.Date;

/**
 * @author chenai
 * @description TODO
 * @date 2022-06-09 20:07
 */
@Service
public class WxAuthServiceImpl implements WxAuthService {
    @Autowired
    WxAuthMapper wxAuthMapper;

    @Autowired
    MarketUserMapper marketUserMapper;

    @Override
    public boolean judgeUsername(String username) {
        return !(wxAuthMapper.judgeUsername(username) > 0);
    }

    @Override
    public boolean judgePhone(String mobile) {
        return !(wxAuthMapper.judgePhone(mobile) > 0);
    }

    @Override
    public void insertNewUser(String username, String password, String mobile, String wxCode) {
        String passwordNew = DigestUtils.md5DigestAsHex(password.getBytes());
        MarketUser marketUser = new MarketUser(null,username,passwordNew, ((byte) 1),null,null,"", ((byte) 0),username,mobile,"",wxCode,"", ((byte) 0),new Date(),new Date(),false);
        marketUserMapper.insert(marketUser);
    }

    @Override
    public void resetPassword(String mobile, String password) {
        String passwordNew = DigestUtils.md5DigestAsHex(password.getBytes());
        wxAuthMapper.resetPassword(mobile, passwordNew);
    }
}
